import socket
import json
from typing import List, Tuple


def main():
    host = "0.0.0.0"
    port = 5010
    skt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    skt.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 8192)
    skt.bind((host, port))
    skt.settimeout(2.0)

    while True:
        try:
            data, addr = skt.recvfrom(1024)
            if not data:
                continue
            data = data.decode("utf-8")
            print(f"Received data from {addr}: {data}")
            try:
                json_data = json.loads(data)
                if isinstance(json_data, list) and len(json_data) == 2:
                    print(f"Parsed JSON: {json_data}")
                else:
                    print("Received non-list JSON data.")
            except json.JSONDecodeError as e:
                print(f"JSON decode error: {e}")
        except socket.timeout:
            print("Socket timeout, no data received.")
        except Exception as e:
            print(f"An error occurred: {e}")
            break
    
    skt.close()

if __name__ == "__main__":
    main()